//
// Created by tianq on 25-1-4.
//
// matrix chain problem
//
// input:
//     c: matrix count,
//     following c lines, each contains 2 numbers wi,hi
// output: minimal multiplication count
//
// hint:
// to multiply 2 matrix A,B Wa = Hb
// mul count: Ha*Wa*Wb
// result: matrix[Ha,Wb] -> [H1,Wn]
//

/*
test data:
6
30 35
35 15
15 5
5 10
10 20
20 25

Expected: 15125
 */


#include <iomanip>
#include <iostream>
#include <vector>
#include <limits>
using namespace std;

int main() {
    int c = 0;
    cin >> c;

    vector<int> w(c), h(c);
    vector M(c, vector<int>(c));

    // x,y stands for position on table, M[x][y] stands for minimum mul for Mx*...*My
    for (int x = 0; x < c; x++) {
        cin >> h[x] >> w[x];
        M[x][x] = 0; // it takes 0 mul to get the matrix itself

        // with new matrix input, we can calc its mul with all previous ones
        for (int y = x - 1; y >= 0; y--) {
            cout << "Calculating M[" << x << "][" << y << "]" << endl;
            int minMul = numeric_limits<int>::max();
            for (int r = y; r < x; r++) {
                //(M[x]*...*M[r])*(M[r+1]*...*M[y])
                int curMul = h[y] * w[r] * w[x] + M[y][r] + M[r + 1][x];
                minMul = minMul < curMul ? minMul : curMul;
                cout << "curMul = " << setw(8) << curMul << " = h[" << y << "] * w[" << r << "] * w[" << x << "]";
                cout << " + MinMul[" << y << "][" << r << "] + MinMul[" << r + 1 << "][" << x << "]";
                cout << "=" << h[y] << "*" << w[r] << "*" << w[x] << "+" << M[y][r] << "+" << M[r + 1][x] << endl;
            }
            M[y][x] = minMul;
            cout << "minMul = " << setw(8) << minMul << endl << endl;
        }

        for (const auto &row: M) {
            for (const auto &col: row)
                cout << setw(8) << col << " ";
            cout << endl;
        }
    }

    cout << M[0][c - 1] << endl;

    return 0;
}
